home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10278 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.clark.net!not-for-mail
  2. From: gusty@clark.net (Harlan Messinger)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: question assignment operator in c++
  5. Date: 6 Mar 1996 23:36:39 GMT
  6. Organization: Clark Internet Services, Inc., Ellicott City, MD USA
  7. Message-ID: <4hl7i7$81a@clarknet.clark.net>
  8. References: <menghua_wang.1.002DB7BE@muccmail.missouri.edu>
  9. NNTP-Posting-Host: explorer.clark.net
  10. Mime-Version: 1.0
  11. Content-Type: TEXT/PLAIN; charset=ISO-8859-1
  12. Content-Transfer-Encoding: 8bit
  13. X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
  14.  
  15. menghua wang (menghua_wang@muccmail.missouri.edu) wrote:
  16. : I do not why the assignment operator can only be overloaded as a member 
  17. : function in a class such as:
  18. :           class myclass {
  19. :               int i;
  20. :           public:
  21. :               myclass operator= (myclass &A) {
  22. :                  i = A.i;
  23. :                  return *this;
  24. :               }
  25. :           };
  26. : Why does not the following frind overloading work?
  27. :               mycalss operator= (myclass &A, myclass &B) {
  28. :                    A.i = B.i;
  29. :                    return A;
  30. :               }
  31.  
  32. I believe it's because each class has a default assignment operator as an
  33. implicit member function. Therefore, if you want to write your own, you
  34. have to overload the existing implied one, which calls for an explicit
  35. member function. That, or perhaps there would be inheritance problems. 
  36.  
  37.